package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;

import com.zzyl.nursing.dto.FamilyMemberDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.MyListVo;
import com.zzyl.nursing.vo.MyVo;
import org.apache.ibatis.annotations.Delete;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-08-26
 */
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto){
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }

    /**
     * 绑定老人
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FamilyMemberDto familyMemberDto){
       return AjaxResult.success(familyMemberService.insertFamilyMember(familyMemberDto)) ;
    }

    /**
     * 根据Id查询老人列表
     * */
    @GetMapping("/my")
    public AjaxResult my(){
        List<MyVo> myVo = familyMemberService.selectMy();
        return success(myVo);
    }

    /**
     * 查看家人列表
     */
    @GetMapping("/list-by-page")
    public AjaxResult listByPage() {
        List<MyListVo> userList = familyMemberService.listByPage();
        return AjaxResult.success(userList);
    }

    /**
     * 解除绑定
     * */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById( Long id){
      return AjaxResult.success(familyMemberService.deleteFamilyMemberElderById(id));
    }



}
